<?php

/*
*
*   Excalibur Content Management System
*   Copyright © 2008 Egor "Sontan" Kuryanovich
*
*   Based on Explay Engine v2.0 by Golovdinov Alexander
*
*   Official site: www.excms.ru
*   Contact e-mail: support@excms.ru
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
*/


if ($EXCMS != 'work') 
{
	header ('Location: ../index.php');
	exit;
}

function site_message ($mess)
{
	global $template;
	$template->set_var ('{MESSAGE}', $mess);
	print $template->display ('site_message.tpl');
}

function site_error ($warn)
{
	global $template;
	$template->set_var ('{MESSAGE}', $warn);
	print $template->display ('site_error.tpl');
}

function block ($block_header, $block_name, $body, $type, $align='')
{
	global $template, $db, $EXCMS, $GLOBAL_USER, $CORE;
	
	if ($type == 't') {
		$template->set_var ('{HEADER}', $block_header);
		$template->set_var ('{NAME}', $block_name);
		$template->set_var ('{BLOCK}', $body);
		($align=='left') ? $CORE->blocks_left .= $template->display ('block.tpl') : $CORE->blocks_right .= $template->display ('block.tpl');
	}
	else include $_SERVER['DOCUMENT_ROOT'].'/'.$body;
}

function past_table ($header, $body, $return = false)
{
	global $template;
	$template->set_var ('{HEADER}', $header);
	$template->set_var ('{BODY}', $body);
	
	if ($return) return  $template->display ('table.tpl');
	else print $template->display ('table.tpl');
}


function get_element ($start, $end) 
{ 
	global $template;
	$file = $template->display ('elements.tpl');
	preg_match ("#$start(.+?)$end#is", $file, $element);
	return $element[1];
}

function past_com_table ($url) 
{
	global $SITE, $GLOBAL_USER, $template;
	if (my_karma() >= '-10') {
		$template->set_var ('{URL}', $url);
		$template->set_var ('{BODY}', $_POST['com_body']);
		$template->set_var ('{GLOBAL_USER_NAME}', $GLOBAL_USER['user_name']);
		$template->set_var ('{GLOBAL_USER_EMAIL}', $GLOBAL_USER['user_email']);
		$template->set_var ('{EDITOR}', print_edit('com_body'));
		if ($SITE['bot_protect'] == 'yes') {
			$template->set_var ("{PROTECT_CODE}", "<span id=\"captcha_image\"><img src=\"/antibot.gif?comment\" align=\"absmiddle\" /></span> <input class=\"form\" size=\"5\" type=\"text\" name=\"code\" maxlength=\"5\" value=\"\">".
				"<br /><small>Не видно? <a href=\"/\" onclick=\"reload_captcha(); return false;\"><small>Обновить!</small></a></small>");
		}
		else {
			$template->set_var ('{PROTECT_CODE}', 'Не нужен ;)');
		}
		$template->set_var ('{JAVASCRIPT}', insert_script ('com_body'));
		print $template->display ('add_comment.tpl');
	}
	else print '<small>У Вас слишком маленькая карма, чтобы добавлять комментарии!</small>';
}
function print_auth_form () {
	global $template;
	print $template->display ('auth_form.tpl');
}

function print_big_authorization ($message, $url) {
	global $template, $SITE;
	$template->set_var ('{URL}', $url);
	$template->set_var ('{SITE_LOGO}', $SITE['site_logo']);
	$template->set_var ('{MESSAGE}', $message);
	print $template->display ('authorization.tpl');
}
function big_message ($mess, $url) {
	global $template;
	$template->set_var ('{URL}', $url);
	$template->set_var ('{MESSAGE}', $mess);
	print $template->display ('message.tpl');
}
function come_back ($name, $url) {
	global $template;
	$template->set_var ('{TEXT}', " <a href='$url'>&larr; Вернуться к $name</a>");
	print $template->display ('simple_table.tpl');
}
function simple_table ($text) {
	global $template;
	$template->set_var ('{TEXT}', $text);
	print $template->display ('simple_table.tpl');
}

function past_navblock ($array) {

	global $template, $CORE;
	
	$list = '';
	
	foreach ($array as $unit) {
		$name = $unit[0];
		$link = $unit[1];
		$var = $unit[2];
		$value = $unit[3];
		
		$template->set_var ('{NAME}', $name);
		$template->set_var ('{LINK}', $link);
		
		if ($value == '_all') {
			if (isset($_GET[$var])) $list .= $template->display ('nav_block/active.tpl');
			else $list .= $template->display ('nav_block/typical.tpl');
		} else {
			if (isset($_GET[$var]) && $_GET[$var] == $value) $list .= $template->display ('nav_block/active.tpl');
			else $list .= $template->display ('nav_block/typical.tpl');
		}
		
	}
	
	$template->set_var ('{LIST}', $list);
		
	$CORE->second_navigation = $template->display ('nav_block/nav_block.tpl');
	
}


